<template>
  <div class="dashboard-container">
    <main>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="序号" width="180"> </el-table-column>
        <el-table-column prop="code" label="编号" width="280">
        </el-table-column>
        <el-table-column prop="name" label="名称" width="280">
        </el-table-column>
        <el-table-column prop="age" label="年龄" width="280"> </el-table-column>
        <el-table-column prop="address" label="地址"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="toPublish(scope.row)" type="primary" size="small"
              >巡查上报</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </main>
    <el-dialog title="巡查上报" :visible="visible" width="30%">
      <div style="display: flex; margin-bottom: 10px">
        <span style="width: 100px">施肥情况</span>
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="publishFrom.diseasesInfo"
        >
        </el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="pbulishInfo()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getTreeList } from "@/api/tree";
import { publishInspectionInfo } from "@/api/protect";
export default {
  name: "Dashboard",
  computed: {
    ...mapGetters(["name"]),
  },
  components: {},
  data() {
    return {
      visible: false,
      title: "新增",
      editID: "",
      deleteID: "",
      searchFrom: {
        currentPage: 1,
        pageSize: 100,
      },
      publishFrom: {
        diseasesInfo: "",
        treeInfoId: "",
        name: "",
        code: "",
      },
      tableData: [
        {
          id: "1",
          code: "20240219",
          name: "千年名树",
          age: "1200",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          id: "2",
          code: "20240219",
          name: "千年名树",
          age: "1200",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          id: "3",
          code: "20240219",
          name: "千年名树",
          age: "1200",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          id: "4",
          code: "20240219",
          name: "千年名树",
          age: "1200",
          address: "上海市普陀区金沙江路 1518 弄",
        },
      ],
    };
  },
  mounted() {
    this.getTreeList();
  },
  methods: {
    getTreeList() {
      getTreeList(this.searchFrom).then((res) => {
        console.log(res);
        this.tableData = res.data;
      });
    },
    toPublish(record) {
      this.publishFrom.treeInfoId = record.id;
      this.publishFrom.name = record.name;
      this.publishFrom.code = record.code;
      this.visible = true;
    },
    pbulishInfo() {
      console.log(this.publishFrom);
      publishInspectionInfo(this.publishFrom).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "上传成功!",
          });
          this.visible = false;
        }
      });
    },
    cancel() {
      this.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
